<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

	<head>
		<meta charset="UTF-8">
		<title>自动回复</title>
		<link rel="stylesheet" href="/dvmini/res/plugins/layui/css/layui.css">
		<link rel="stylesheet" href="/dvmini/res/css/Layuiglobal.css">
		<link rel="stylesheet" href="/dvmini/res/plugins/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="http://at.alicdn.com/t/font_191348_aee57zbh6jyk3xr.css">
		<link rel="stylesheet" href="/dvmini/res/css/basic.css">	
	</head>

	<body class="wrap">
		<div id="keywords-form">
		<div class="popupbox">
			<div class="popupbos">
				<div class="layui-form">
					<div class="layui-form-item">
						<label class="layui-form-label">关键词：</label>
						<div class="layui-input-inline" style="width:250px;">
							<input type="text" name="keywords" lay-verify="required" placeholder="关键词" autocomplete="off" id="text1" class="layui-input" value="">
						</div>
						<div class="layui-form-mid layui-word-aux">多个关键词请用英文“ , ”分隔</div>
					</div>
					<form class="layui-form">
						<div class="layui-form-item">
							<label class="layui-form-label">是否转人工客服：</label>
							<div class="layui-input-inline">
								<input type="radio" name="isRedirectStaff" lay-filter="isRedirectStaff" value="0" title="否" checked="ture">
								<input type="radio" name="isRedirectStaff" lay-filter="isRedirectStaff" value="1" title="是" >
							</div>
						</div>
					</form>
					
					<div class="layui-form-item layui-form-text Redirectbox">
						<label for="" class="layui-form-label">回复内容：</label>
						<div class="layui-input-inline" style="width:65%;">
							<textarea class="layui-textarea" name="content" lay-verify="required" id="saytext" placeholder="请输入内容" style="height:100px;" ></textarea>
							<i class="iconfont icon-xiaolian emotion"></i><div class="layui-form-mid layui-word-aux" style="padding-top:10px;line-height:28px;">多条回复内容用“ | ”分隔</div>
						</div>
						<div class="layui-form-mid layui-word-aux " style="margin-left:150px;">注: 活动结束或过期后会自动停止推送</div>
					</div>

					
					<div class="layui-form-item" style="margin-left:140px;margin-top:30px;">
						<button class="layui-btn Sumbit">提交</button>
						<button class="layui-btn layui-btn-primary resetBtn">重置</button>
					</div>
					
				</div>
				

			</div>
		</div>
	</div>

	</body>
	<script src='/dvmini/res/js/jquery.min.js'></script>
	<script type="text/javascript" src="/dvmini/res/js/jquery.qqFace.js"></script>
	<script src="/dvmini/res/plugins/layui/layui.js" charset="utf-8"></script>
	<script src="/dvmini/res/js/me.js"></script>
	
	<script>
		layui.use(['element', 'form', 'layedit', 'layer', 'jquery', 'laypage'], function() {
			var element = layui.element();
			var form = layui.form(); //初始化弹窗组件
			var layedit = layui.layedit; //初始化富文本
			var editIndex = layedit.build("LAY_demo_editor"); //实例化一个富文本
			var layer = layui.layer;
			var laypage = layui.laypage;
			var page_ = 1;
			var ispush = false ;
			var ispushAdd = false ;
			
			//初始化数据
			var id = getUrl_G("id");
			if(id>0){
				$.post("/dvmini/autoreply/getAutoReply",{id:id},function(data){
					console.log(data)
					$("input[name=keywords]").val(data.data.keywords);
					if(data.data.isredirectstaff==true){
						$("input[name=isRedirectStaff]").eq(1).attr("checked",true);
					}else{
						$("input[name=isRedirectStaff]").eq(0).attr("checked",true);
					}
					form.render();
					
				})
			}
			 $(".resetBtn").on("click",function(){
					$("input[name=keywords]").val("");
					$("input[name=isRedirectStaff]").eq(0).attr("checked",true);
					$(".Redirectbox").show();
					$("textarea[name=content]").val("");
					form.render();
					
				}) 
			$(".Sumbit").on("click",function(){
					var keywords=$("input[name=keywords]").val();
					var isRedirectStaff=$("input[name=isRedirectStaff]:checked").val();
					var content="";
					if(keywords==""){
						top.layer.msg("请填写关键词");
						return false;
					}
					if(isRedirectStaff=="0"){
						isRedirectStaff=false;
						content=$("textarea[name=content]").val();
						if(content==""){
							top.layer.msg("请填写回复内容");
							return false;
						}
					}else if(isRedirectStaff=="1"){
						isRedirectStaff=true;
					}
					
					 if(id>0){
						$.post("/dvmini/autoreply/updateAutoreply",{
							id:id,
							keywords:keywords, 
							isRedirectStaff:isRedirectStaff,
							content:content
						},function(data){
							if(data.code==0){
								top.layer.msg("修改成功");
							}
						});
					}else{
						 $.post("/dvmini/autoreply/addAutoreply",{
							 id:id,
							keywords:keywords, 
							isRedirectStaff:isRedirectStaff,
							content:content
						},function(data){
							if(data.code==0){
								top.layer.msg("添加成功");
							}
						}); 
					}  
					 form.render();
					
			})
			
			
			form.render() ;
			//显示自动回复信息
		function getReplyInfo() {
				$.post( "http", {
					data:data
				}, function(data) {
					if(data.data!== null) {
						console.log(data)
						$('textarea[name=attention]').html(replace_em(data.data.content));
					}
				})
			}

			//获取自动回复类型
			function getMenuType() {
				var value = "";
				var radio = $("input[name=isRedirectStaff]");
				for(var i = 0; i < radio.length; i++) {
					if(radio[i].checked == true) {
						value = radio[i].value;
						break;
					}
				}
				return value;
			}
		
			
			/*是否转人工客服切换*/
			form.on('radio(isRedirectStaff)', function(data) {
				if(this.value == 1) {
					$('.Redirectbox').hide();
				} else {
					$('.Redirectbox').show();
				}
			});

			//切换自动回复类型
			form.on('radio(keytype)', function(data) {
				if(this.value == 1) {
					$('.Redirectbox').hide();
					$('radio(isRedirectStaff)').attr("checked",true);
					form.render();
				} else {
					$('.Redirectbox').show();
					$('radio(isRedirectStaff)').attr("checked",false);
					form.render();
					
				}
			});
				
			
			$(function(){
				$('.emotion').qqFace({
					id : 'facebox', 
					assign:'saytext', 
					path:'/dvmini/res/arclist/'	//表情存放的路径
			
				});
			});

		})
		
		
	</script>

</html>